<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;

/**
 * Class Product
 *
 * @property int $id
 * @property string|null $name
 * @property int|null $class_id
 * @property int|null $time_unit
 * @property string|null $rate
 * @property string|null $money
 * @property string|null $detail
 * @property string|null $content
 * @property string|null $ceiling
 * @property string|null $sale_time
 * @property string|null $commission
 * @property string|null $commission_type
 * @property string|null $pay_type
 * @property string|null $pay_long
 * @property int|null $pay_time_unit
 * @property int|null $long_time
 * @property string $results_rate
 * @property int|null $year_type
 * @property string|null $state
 * @property Carbon|null $create_time
 * @property string|null $app_status
 * @property string|null $wx_xcx_status
 * @property string|null $pc_status
 * @property string|null $remark
 * @property Carbon|null $update_time
 * @property string|null $tag
 *
 * @property ProductClass|null $product_class
 * @property Collection|ExcelFile[] $excel_files
 * @property Collection|Order[] $orders
 *
 * @package App\Models
 */
class Product extends Model
{
	protected $table = 'product';

	protected $casts = [
		'class_id' => 'int',
		'time_unit' => 'int',
		'pay_time_unit' => 'int',
		'long_time' => 'int',
		'year_type' => 'int'
	];

	protected $fillable = [
		'name',
		'class_id',
		'time_unit',
		'rate',
		'money',
		'detail',
		'content',
		'ceiling',
		'sale_time',
		'commission',
		'commission_type',
		'pay_type',
		'pay_long',
		'pay_time_unit',
		'long_time',
		'results_rate',
		'year_type',
		'state',
		'app_status',
		'wx_xcx_status',
		'pc_status',
		'remark',
		'tag'
	];

    protected $attributes = [
        'state' => '1', // 1在售 2下架
        'app_status' => '1', // 1展示 2不展示
        'wx_xcx_status' => '1', // 1展示 2不展示
        'pc_status' => '1', // 1展示 2不展示
    ];

	public function product_class()
	{
		return $this->belongsTo(ProductClass::class, 'class_id');
	}

	public function excel_files()
	{
		return $this->hasMany(ExcelFile::class);
	}

	public function orders()
	{
		return $this->hasMany(Order::class);
	}
}
